package com.ego.controller;

import com.ego.commons.pojo.EasyUIDatagrid;
import com.ego.commons.pojo.EgoResult;
import com.ego.pojo.TbItemParam;
import com.ego.service.TBItemParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Title
 * @Author Lyg
 * @Description:
 */
@RestController
public class TbItemParamController {

    @Autowired
    private TBItemParamService tbItemParamService;
    //列表查询
    @RequestMapping("/item/param/list")
    public EasyUIDatagrid itemParamList(int page,int rows){

        return tbItemParamService.itemParamList(page,rows);
    }
    //根据商品类目id查询对应规格参数：此方法 新增商品和新增规格参数两个地方使用
    @RequestMapping("/item/param/query/itemcatid/{itemCatId}")
    public EgoResult itemParamQueryItemCatid(@PathVariable long itemCatId){
        return tbItemParamService.itemParamQueryItemCatid(itemCatId);
    }
    //新增
    @RequestMapping("/item/param/save/{itemCatId}")
    public EgoResult itemParamSave(@PathVariable long itemCatId, TbItemParam tbItemParam){
        //设置规格参数的类目id
        tbItemParam.setItemCatId(itemCatId);
        return tbItemParamService.insert(tbItemParam);
    }

    //批量删除
    @RequestMapping("/item/param/delete")
    public EgoResult itemParamDelete(@RequestParam List<Long> ids){

        return tbItemParamService.deleteByIds(ids);
    }
}
